package com.meilai.project.util.either;

import java.util.Optional;

/**
 * @author 张驰
 * @date 2020/12/3 17:15
 */
public class Right<A, B> implements Either<A, B> {
    private final boolean type = true;
    private B data;

    public Right(B data) {
        this.data = data;
    }

    @Override
    public Optional<B> getRightData() {
        return Optional.ofNullable(data);
    }

    @Override
    public Optional<A> getLeftData() {
        return Optional.empty();
    }

    @Override
    public boolean isRight() {
        return type;
    }

    @Override
    public boolean isLeft() {
        return !type;
    }

    public B getData() {
        return data;
    }

    public void setData(B data) {
        this.data = data;
    }

}
